package com.zz.ecommerce.searchManage.ent;

import com.zz.ecommerce.common.CommonDao;
import com.zz.ecommerce.common.GridRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by fanshilei on 2015/12/11.
 * <p/>
 * 经济主体备案 Service
 */
@Service
public class EntRegDistService {

    private static final String T_ENT_REG_DIST = "T_ENT_REG_DIST";

    @Autowired
    private EntRegDistDao entRecordDao;
    @Autowired
    private CommonDao commonDao;

    /**
     * 经营主体备案信息查询列表
     *
     * @param gridRequest
     * @param tEntRegDist
     * @param searchVal
     * @return
     */
    @Transactional(readOnly = true)
    public List<TEntRegDist> queryEntRecords(GridRequest gridRequest, TEntRegDist tEntRegDist, String searchVal) {
        //searchVal 为portal 首页传入参数
        if (StringUtils.isEmpty(searchVal)) {
            return entRecordDao.queryEntRecords(T_ENT_REG_DIST, tEntRegDist, gridRequest.getStart(),
                                                gridRequest.getEnd(),
                                                gridRequest.getSortOrder());
        } else {
            return entRecordDao.queryEntRecordsBySearch(T_ENT_REG_DIST, searchVal, gridRequest.getStart(),
                                                        gridRequest.getEnd(),
                                                        gridRequest.getSortOrder());
        }
    }

    @Transactional(readOnly = true)
    public long getEntRecordsCnt(TEntRegDist tEntRegDist, String searchVal) {
        //searchVal 为portal 首页传入参数
        if (StringUtils.isEmpty(searchVal)) {
            return entRecordDao.getEntRecordsCnt(T_ENT_REG_DIST, tEntRegDist);
        } else {
            return entRecordDao.getEntRecordsSearchCnt(T_ENT_REG_DIST, searchVal);
        }

    }
}
